//
//  PlayerView.m
//  NewMusic
//
//  Created by dllo on 15/11/14.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "PlayerView.h"
#import <UIImageView+WebCache.h>
@interface PlayerView ()<UIScrollViewDelegate>

@property (nonatomic, retain) UIScrollView *scrollerView;
@property (nonatomic, retain) UIPageControl *pageC;
@end

@implementation PlayerView

- (void)dealloc
{
    [_imageViewDiscBack release];
    [_imageViewDisc release];
    [_scrollerView release];
    [_pageC release];
    [super dealloc];
}
//改写初始化
- (instancetype)initWithFrame:(CGRect)frame
                 imageViewUrl:(NSString *)url
                   songerName:(NSString *)name
                        album:(NSString *)album
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatSubView:url songerName:name album:album];
    }
    return self;
}
//创建视图
- (void)creatSubView:(NSString *)url
          songerName:(NSString *)name
               album:(NSString *)album
{
    self.userInteractionEnabled = YES;
    //scoller创建
    self.scrollerView = [[UIScrollView alloc] initWithFrame:self.frame];
    self.scrollerView.contentSize = CGSizeMake(self.frame.size.width * 2, 0);
    self.scrollerView.delegate = self;
    self.scrollerView.showsHorizontalScrollIndicator = NO;
    self.scrollerView.pagingEnabled = YES;
    self.scrollerView.userInteractionEnabled = YES;
    [self addSubview:self.scrollerView];
    [_scrollerView release];
    //scroller第一个视图创建
    UIView *rootView = [[UIView alloc] initWithFrame:self.frame];
    [self.scrollerView addSubview:rootView];
    [rootView release];
    //第二个创建
    UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(self.frame.size.width, 0, rootView.frame.size.width, rootView.frame.size.height)];
    secondView.userInteractionEnabled = YES;
    [self.scrollerView addSubview:secondView];
    [secondView release];
    //pageController创建
    self.pageC = [[UIPageControl alloc] initWithFrame:CGRectMake(self.frame.size.width / 2 - 25, 410, 50, 20)];
    self.pageC.numberOfPages = 2;
    [self addSubview:self.pageC];
    self.pageC.userInteractionEnabled = YES;
    [self.pageC addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
    [_pageC release];
    //唱片背景创建
    self.imageViewDiscBack = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width / 2 - 150, 65, 300, 300)];
    self.imageViewDiscBack.image = [UIImage imageNamed:@"BF-changpian"];
    [rootView addSubview:self.imageViewDiscBack];
    self.imageViewDiscBack.userInteractionEnabled = YES;
    self.imageViewDiscBack.layer.masksToBounds = YES;
    self.imageViewDiscBack.layer.cornerRadius = 150;
    [_imageViewDisc release];
    //唱片图标创建
    self.imageViewDisc = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 280, 280)];
    self.imageViewDisc.layer.cornerRadius = 140;
    self.imageViewDisc.layer.masksToBounds = YES;
    self.imageViewDisc.userInteractionEnabled = YES;
    [self.imageViewDiscBack addSubview:self.imageViewDisc];
    [_imageViewDisc release];
        
    // 唱片创建
    UIView *viewLeft = [[UIView alloc] initWithFrame:CGRectMake(120, 30, 20, 2)];
    viewLeft.backgroundColor = [UIColor colorWithRed:80 / 255.0 green:80 / 255.0 blue:80 / 255.0 alpha:1.0];
    [rootView addSubview:viewLeft];
    [viewLeft release];
    UIView *viewRight = [[UIView alloc] initWithFrame:CGRectMake(240, 30, 20, 2)];
    viewRight.backgroundColor = [UIColor colorWithRed:80 / 255.0 green:80 / 255.0 blue:80 / 255.0 alpha:1.0];
    [rootView addSubview:viewRight];
    [viewRight release];
    self.labelName = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width / 2 - 50, 10, 100, 40)];
    self.labelName.userInteractionEnabled = YES;
    self.labelName.text = name;
    self.labelName.textColor = [UIColor colorWithRed:200 / 255.0 green:200 / 255.0  blue:200 / 255.0  alpha:1.0];
    self.labelName.textAlignment = NSTextAlignmentCenter;
    self.labelName.font = [UIFont boldSystemFontOfSize:16.0];
    [rootView addSubview:self.labelName];
    [_labelName release];
    
    //详情创建
    self.labelSonger = [[UILabel alloc] initWithFrame:CGRectMake(30, 20, 150, 50)];
    self.labelSonger.text = [NSString stringWithFormat:@"歌手: %@", name];
    self.labelSonger .textColor = [UIColor colorWithRed:200 / 255.0 green:200 / 255.0  blue:200 / 255.0  alpha:1.0];
    self.labelSonger.userInteractionEnabled = YES;
    self.labelSonger.textAlignment = NSTextAlignmentLeft;
    self.labelSonger.font = [UIFont boldSystemFontOfSize:18.0];
    [secondView addSubview:self.labelSonger];
    [_labelSonger release];
    UIView *viewLineOne = [[UIView alloc] initWithFrame:CGRectMake(15, 70, 360, 1)];
    viewLineOne.backgroundColor = [UIColor colorWithRed:150 / 255.0 green:150 / 255.0 blue:150 / 255.0 alpha:1.0];
    [secondView addSubview:viewLineOne];
    [viewLineOne release];
    self.labelalbum = [[UILabel alloc] initWithFrame:CGRectMake(30, 90, 150, 50)];
    self.labelalbum.text = [NSString stringWithFormat:@"专辑: %@", album];
    self.labelalbum.textColor = [UIColor colorWithRed:200 / 255.0 green:200 / 255.0  blue:200 / 255.0  alpha:1.0];
    self.labelalbum.userInteractionEnabled = YES;
    self.labelalbum.textAlignment = NSTextAlignmentLeft;
    self.labelalbum.font = [UIFont boldSystemFontOfSize:18.0];
    [secondView addSubview:self.labelalbum];
    [_labelalbum release];
    UIView *viewLineTwo = [[UIView alloc] initWithFrame:CGRectMake(15, 140, 360, 1)];
    viewLineTwo.backgroundColor = [UIColor colorWithRed:150 / 255.0 green:150 / 255.0 blue:150 / 255.0 alpha:1.0];
    [secondView addSubview:viewLineTwo];
    [viewLineTwo release];
}
- (void)pageAction:(UIPageControl *)sender
{
    [self.scrollerView setContentOffset:CGPointMake(sender.currentPage * self.frame.size.width, 0) animated:YES];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    self.pageC.currentPage = self.scrollerView.contentOffset.x / self.frame.size.width;
}
@end
